﻿using System.Web.Mvc;
using Sharp.Portal.Mvc.List;

namespace Sharp.WebBooter.Areas.Platform
{
    public class ViewModelFilter: IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            SharpList sharpList;
            if (filterContext.Result is Ext.Net.MVC.PartialViewResult)
            {
                var res = ((Ext.Net.MVC.PartialViewResult) filterContext.Result);
                sharpList = res.Model as SharpList;
            }
            else
            {
                var viewData = filterContext.Controller.ViewData;
                sharpList = viewData.Model as SharpList;
            }
            if (sharpList == null) return;

            sharpList.Preference = typeof(UserPortalConfig);
            sharpList.SystemConfig = typeof(PlatformInfo);
        }
    }
}
